<?php
class App_Source_Structure_Entity extends Mozg_Property_Params
{
	public function GetUrl()
	{
		$url = $this->Get('url');
		if (!strlen($url))
		{
			$url = Mozg::Lib('Str')->GetTraslit($this->GetName());
			$this->SetUrl($url);
		}

		return $url;
	}

	public function GetPageParams()
	{
		$this->LoadFullData();
		return $this->Get('pageParams');
	}

	public function GetContentBody()
	{
		$this->LoadFullData();
		return $this->Get('contentBody');
	}

	public function GetModuleParams()
	{
		$this->LoadFullData();

		if (!$this->HasSet('moduleParams'))
		{
			$this->SetModuleParams(array());
		}

		return $this->Get('moduleParams');
	}

	public function SetModuleParams($params)
	{
		$pageType = $this->GetPageType();
		$pageTypes = Mozg_Cfg::Get('global/structure')->GetPageTypes();

		$pageParamsPath = '';
		if (isset($pageTypes[$pageType]['fieldparams']))
		{
			$pageParamsPath = $pageTypes[$pageType]['fieldparams'];
		}

		$this->Set('moduleParams', Mozg_Entity::Get($pageParamsPath, $params));
	}

	public function SetPageType($pageType)
	{
		$currentPageType = $this->Get('pageType');
		if ($currentPageType == $pageType) return $this;

		$this->Set('pageType', $pageType);

		if ($this->HasSet('moduleParams'))
		{
			$this->SetModuleParams($this->Get('moduleParams'));
		}
	}
}